//
//  File.swift
//
//
//  Created by yk-mengqingling on 2021/2/1.
//
import Foundation
import SVProgressHUD

public enum JLHud {
    /// 海外使用时先赋值
    public static var defaultTip: String = "请稍候..."
    
    public static func setMaxSupportedWindowLevel(_ level: UIWindow.Level) {
        SVProgressHUD.setMaxSupportedWindowLevel(level)
    }
    
    /// HUD 配置
    /// - Parameters:
    ///   - font: 字体
    ///   - inteval: 自动消失时间
    public static func config(with font: UIFont, autoDismiss inteval: TimeInterval) {
        SVProgressHUD.setDefaultStyle(SVProgressHUDStyle.custom)
        SVProgressHUD.setMinimumDismissTimeInterval(inteval)
        SVProgressHUD.setFont(font)
        SVProgressHUD.setMinimumSize(CGSize(width: 70, height: 20))
        SVProgressHUD.setRingRadius(10)
        SVProgressHUD.setCornerRadius(10)
        SVProgressHUD.setBackgroundColor(UIColor.black.withAlphaComponent(0.9))
        SVProgressHUD.setForegroundColor(UIColor.white)
    }
    
    public static func showWait(tip:String = defaultTip, _ isFocus: Bool = false) {
        if isFocus {
           SVProgressHUD.setDefaultMaskType(SVProgressHUDMaskType.clear)
        } else {
           SVProgressHUD.setDefaultMaskType(SVProgressHUDMaskType.none)
        }
        SVProgressHUD.show(withStatus: tip)
    }

    public static func dismiss(_ isFocus: Bool = false) {
        if isFocus {
            SVProgressHUD.setDefaultMaskType(SVProgressHUDMaskType.clear)
        } else {
            SVProgressHUD.setDefaultMaskType(SVProgressHUDMaskType.none)
        }
        SVProgressHUD.dismiss()
    }


    public static func showInfo(tip: String?, _ isFocus: Bool = false) {
        guard let tip = tip else { return }
        if isFocus {
            SVProgressHUD.setDefaultMaskType(SVProgressHUDMaskType.clear)
        } else {
            SVProgressHUD.setDefaultMaskType(SVProgressHUDMaskType.none)
        }
        SVProgressHUD.showInfo(withStatus: tip)
    }

    public static func showSuccess(tip: String?, _ isFocus: Bool = false) {
        guard let tip = tip else { return }
        if isFocus {
            SVProgressHUD.setDefaultMaskType(SVProgressHUDMaskType.clear)
        } else {
            SVProgressHUD.setDefaultMaskType(SVProgressHUDMaskType.none)
        }
        SVProgressHUD.showSuccess(withStatus: tip)
    }

    public static func showFail(tip: String?, _ isFocus: Bool = false) {
        guard let tip = tip else { return }
        if isFocus {
            SVProgressHUD.setDefaultMaskType(SVProgressHUDMaskType.clear)
        } else {
            SVProgressHUD.setDefaultMaskType(SVProgressHUDMaskType.none)
        }
        SVProgressHUD.showInfo(withStatus: tip)
    }

    public static func showText(_ text: String?, _ isFocus: Bool = false) {
        guard let tip = text else { return }
        if isFocus {
            SVProgressHUD.setDefaultMaskType(SVProgressHUDMaskType.clear)
        } else {
            SVProgressHUD.setDefaultMaskType(SVProgressHUDMaskType.none)
        }
        SVProgressHUD.showInfo(withStatus: tip)
    }

    public static func showProgress(progress: Float, _ isFocus: Bool = false) {
        if isFocus {
            SVProgressHUD.setDefaultMaskType(SVProgressHUDMaskType.clear)
        } else {
            SVProgressHUD.setDefaultMaskType(SVProgressHUDMaskType.none)
        }
        SVProgressHUD.showProgress(progress, status: "\(Int(progress * 100))%")
    }
}


